//
//  ConrollerManager.m
//  DeepBreathing
//
//  Created by DreamHack on 15-12-18.
//  Copyright (c) 2015年 DreamHack. All rights reserved.
//

#import "ControllerManager.h"
#import "LeftViewController.h"
#import "RightViewController.h"

@interface ControllerManager ()

@property (nonatomic, strong)APPLEViewController * drawerVC;
@property (nonatomic, strong)BANANAViewController * tabVC;
@property (nonatomic, strong) UIViewController * rootViewContorller;

@end

@implementation ControllerManager

+ (instancetype)sharedManager
{
    static ControllerManager * manager ;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[ControllerManager alloc] init];
    });
    return manager;
}

- (UIViewController *)rootViewContorller
{
    if (!_rootViewContorller) {
        UINavigationController * navc = [[UINavigationController alloc] initWithRootViewController:self.drawerVC];
        navc.navigationBarHidden = YES;
        _rootViewContorller = navc;
    }
    return _rootViewContorller;
}

- (APPLEViewController *)drawerVC
{
    if (!_drawerVC) {
        UINavigationController * navc = [[UINavigationController alloc] initWithRootViewController:self.tabVC];
        navc.navigationBarHidden = YES;
//        _drawerVC =   [[APPLEViewController alloc]initWithMainViewController:navc leftViewController:[[LeftViewController alloc]init]];
        _drawerVC = [[APPLEViewController alloc]initWithMainViewController:navc leftViewController:[[LeftViewController alloc]init] rightViewController:[[RightViewController alloc]init]];
    }
    return _drawerVC;
}

- (BANANAViewController *)tabVC
{
    if (!_tabVC) {
        NSArray *controllerClassNames = @[@"RecordViewController",@"AssessViewController",@"MedicineViewController",@"KnowledgeViewController",@"DiagnoseViewController"];
        NSMutableArray * normalImages = [NSMutableArray arrayWithCapacity:5];
        NSMutableArray * selectedImages = [NSMutableArray arrayWithCapacity:5];
        NSMutableArray * viewControllers = [NSMutableArray arrayWithCapacity:5];
        
        [controllerClassNames enumerateObjectsUsingBlock:^(NSString * name, NSUInteger idx, BOOL *stop) {
            UIViewController * controller = [[NSClassFromString(name) alloc] init];
            [viewControllers addObject:controller];
//            controller.view.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.f green:arc4random()%256/255.f blue:arc4random()%256/255.f alpha:1];
            NSString * normalImageName = [NSString stringWithFormat:@"100%lu-0.png",idx];
            NSString * selectedImageName = [NSString stringWithFormat:@"100%lu-1.png",idx];
            [normalImages addObject:[UIImage imageNamed:normalImageName]];
            [selectedImages addObject:[UIImage imageNamed:selectedImageName]];
            
        }];
        
        BANANAViewController *tabController = [[BANANAViewController alloc]initWithViewControllers:viewControllers normalStateImage:normalImages selectedStateImage:selectedImages];
       
        _tabVC = tabController;
    }
    return _tabVC;
}

@end
